Freescale-
EthernetAPI
 
General Info
Properties
Methods
Events
User Types
Typical Usage



Embedded Beans
CPU Beans
About Beans
Bean Categories



Bean icon
 
 Bean FreescaleEthernetAPI
 
NE64 ethernet API routines

Typical usage of the bean in user's code.

Typical Usage:

This example shows simple implementation of ICMP echo example and Simple ARP (Address Resolution Protocol).
It is assumed that these properties are set to correct values:

Cpu bean:
    Properties:
    • Oscillator frequency is set to 25MHz. It is needed for proper functionality of internal EPHY device (Ethernet Physical Transceiver)
    • Internal bus clock is set to 20, 25, 30, 33, 40 or 50Mhz.
    • Register block mapping is set to $0000
    • Internal RAM mapping is set to $2000

    Build options:
    For ROM/RAM area - change the RAM for compiler/linker because the EMAC device uses the beginning of the RAM for receive and transmit buffers. The occupied size depends on the Buffer mapping of inherited EMAC bean. If you use RX and TX size buffer 1536 bytes then change these values:
    • Address - change to 3200 hex
    • Size - change to 800 hex
Ethernet API bean:
MAIN.C
#include "MotTypes.h"
#include "ne64config.h"
#include "ne64driver.h"
#include "ne64api.h"
#include "ne64debug.h"
#include "mBuf.h"

#include "arp.h"
#include "ip.h"


extern tU16 gotxflowc;         /**Global Variable For Determination
                                  of Flow Control Packets are sent in Full Duplex*/
extern tU08 gotlink;           /**Global Variable For Determination if link is active*/

#if ZERO_COPY
#else
  tU08 ourbuffer [1518];    /** Space for packet temporary storage if zero copy not used */
#endif

#if USE_SWLED
tU16 LEDcounter=0;
#endif

/******************************************************************************
*
* Add user application code here
******************************************************************************/
void MyAppInit()
{
}

/******************************************************************************
*
* Add user application code here
******************************************************************************/
void MyAppLinked()
{
}

/******************************************************************************
*
* Add user application code here
******************************************************************************/
void MyAppNotLinked()
{
}

void main(void)
{
/*
*        Step 1: Intialize CRG, SCI, EMAC, and EPHY
*  Main Loop: Process Received Packets
*
*
* NOTE.- THIS EXAMPLE IS BUILD WITH THE FOLLOWING CONFIGURATIONS (see ne64config.h)*
*
*  WORD_ACCESS    1 - use word access
*  ZERO_COPY      1 - use zero copy
*  RX_POLL_MODE   0 - use buffer interrupts
*/
  /*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/
  PE_low_level_init();
  /*** End of Processor Expert internal initialization.                    ***/

  //=========================
  //Variables
  //=========================
  mBufInit ();

  /* Ethernet Init */
  gotxflowc = 0;                 /* Do not send or respond to pause frames unless */
  EtherInit();                         /* Initialize MAC and PHY                         */
#if USE_EXTBUS
  ExternalBusCfg();
#endif

  /* Add user application init code here */
  MyAppInit();

  for (;;)  /* do forever */
  {
#if USE_SWLED
    UseSWLedRun();
#endif
    if (gotlink)
    {
        /* Link is UP - Add user application code here */
        if (NE64ValidFrameReception ())
        {
            void ProcessPacket(void *ptr);   /* Forward declaration */
            MBUF* ptr;
            ptr = (MBUF *)NE64GetCurrentReceivedFrame ();
            ProcessPacket (ptr->data);
            NE64FreeReceiveBuffer ();

            /* Link is UP - Add user application code here */
            MyAppLinked();
        }

        #if XFLOWC
            /* send pause frames - if agreement with auto negotiation pause resolution */
            if (gotxflowc)  EtherPause(SEND_PAUSE, PAUSE_TIME);
        #endif
    }
    else
    {

        /* Link is DOWN - Add user application code here */
        MyAppNotLinked();

    }   /* if (gotlink) */

  } /* Forever loop */

  ...
}
void ProcessPacket(void *ptr)
{
    typedef struct
      {
       tU08 destination [6]; /** destination address */
       tU08 source      [6]; /** source address */
       tU16 type;            /** frame type */
      } EthHeader;

    switch ( ((EthHeader *)ptr)->type)
    {
        case 0x0806:    /* ARP Received */
            _DEBUGT("\r\nGOTARP");
            HandleARP (ptr);
            break;

        case 0x0800:    /* IP Received  */
            _DEBUGT("\r\nGOTIP");
            HandleIP (ptr);
            break;

        case 0x86DD:
            /* Add your IPv6 handler here */
            break;

        case 0x8808:    /* Pause frame Received */
            /* Add your PAUSE handler here */
            break;

        default:        /* Huh? */
            /* Add your handler here */
            break;
    }
}

For more about typical usage of the bean code please refer to the page Bean Code Typical Usage.


©1997-2004, UNIS, Ltd.